<?php
if(!empty($_POST)){
	include ("paddresource.php");
}else{
define("ROOT_PATH",str_replace("admin","",dirname($_SERVER['PHP_SELF'])));

$sids = $_SESSION["ArraySec"];
if($_SESSION['Permit']==1)
 { 
$sql = "Select id,vi_title from tblarticle";
 }
   else
$sql = "Select id,vi_title from tblarticle where section_id  in ($sids)";
$articles = mysql_query($sql)or die(mysql_error());

?>
<script type="text/javascript" src="<?php echo ROOT_PATH."ckfinder/ckfinder.js"?>">
</script>
<script type="text/javascript">
function addResource(){
	var frm = document.frmAddResource;
	
	var vi_name = frm.vi_name.value;
	var en_name = frm.en_name.value;
	var link = frm.link.value;
	var msg= "";
	
	alert(document.getElementsByName("vi_name")[0].value);
	if(vi_name==""){
		msg+="Thiếu tên tài nguyên trong Tiếng Việt.\n";
	}
	if(en_name==""){
		msg+="Thiếu tên tài nguyên trong Tiếng Anh.\n";
	}
	
	
	if(link==""){
		msg+="Thiếu liên kết của tài nguyên.\n";
	}
	if(msg!=""){
		alert(msg);
	}else{
		frm.submit();
	}
}
function BrowseServer()
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.basePath = '<?php echo str_replace("admin","",ROOT_PATH)."ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( 'link' ).value = fileUrl ;
		//document.getElementById( 'img' ).src = fileUrl;
		
	}
	finder.popup() ;

	
}
</script>
<form name="frmAddResource" method="post">
	<table width="100%">
		<tr><th colspan="2" style="height:30px;background: #008000; color: white;">Thêm tài nguyên</th></tr>

		<tr>
			<td>
				<b>Tên Tiếng Việt</b>
			</td>
			<td>
				<input type="text" name="vi_name" size="60"></input>
			</td>
		</tr>
		<tr>
			<td>
				<b>Tên Tiếng Anh</b>
			</td>
			<td>
				<input type="text" name="en_name" size="60"></input>
			</td>
		</tr>
		
		<tr>
			<td>
				<b>Link</b>
			</td>
			<td>
				<input type="text" id="link" name="link" size="60" ></input>
				<input type="button" name="btnBrowser" value="Chọn file" onclick="BrowseServer();" />
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="button" onclick="addResource();" value="Thêm"></input>
				<input type="reset"  value="Làm lại"></input>
			</td>
		</tr>
	</table>
</form>
<?php }?>